import systemStore from '@/store/modules/system'

export default {
    mounted(el:any, binding:any) {
        checkPermission(el, binding)
    },
    updated(el:any, binding:any) {
        checkPermission(el, binding)
    },
}

const checkPermission = (el:Element, binding:any) => {
    const { value = '' } = binding
    const permissions:any = systemStore().permissions
    const list:string[] = value.split(',')
    let isDelete:boolean = true

    list.forEach((val:string) => {
        if (val) {
            const flag = permissions[val] || false
            console.log(val, flag)
            if (flag === true) {
                isDelete = false
            }
        }
    })
    if (isDelete === true) {
        el.parentNode && el.parentNode.removeChild(el)
    }
   
}